package com.heima.jopo.web;

import com.heima.jopo.obj.UserInfo;
import com.heima.jopo.utilconn.GetConn;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * 登录验收账号密码
 */
public class LoginVerify {

    //登录验证
    public void loginVer(String account,String pass)throws Exception{

        Connection conn = GetConn.getConn();

        String sql="select * from t_user_info where phone=?";
        try {
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1,account);
            ResultSet resultSet = ps.executeQuery();
            UserInfo userInfo=null;

            while (resultSet.next()){
                userInfo=new UserInfo();
                String phone = resultSet.getString("phone");
                String passwrod = resultSet.getString("passwrod");
                userInfo.setPhone(phone);
                userInfo.setPasswrod(passwrod);
            }

            if (userInfo==null){
                throw new Exception("账号不存在");
            }
         if (!userInfo.getPasswrod().equals(pass)){
             throw new Exception("密码错误");
         }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            //关流
        }


    }

}
